package biz.obake.team.touchprotector.features.shake;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import biz.obake.team.touchprotector.g.c;
import biz.obake.team.touchprotector.g.d;
import java.util.Locale;
import java.util.Map;

public class b extends biz.obake.team.touchprotector.d.b implements SensorEventListener {

    /* renamed from: d  reason: collision with root package name */
    private d f1681d;
    private boolean e = false;
    private Handler f = new Handler();
    private long g;

    class a implements Runnable {
        a() {
        }

        public void run() {
            b.this.j();
        }
    }

    /* renamed from: biz.obake.team.touchprotector.features.shake.b$b  reason: collision with other inner class name */
    private class C0077b {

        /* renamed from: a  reason: collision with root package name */
        boolean f1683a;

        /* renamed from: b  reason: collision with root package name */
        boolean f1684b;

        /* renamed from: c  reason: collision with root package name */
        boolean f1685c;

        /* renamed from: d  reason: collision with root package name */
        boolean f1686d;
        boolean e;
        boolean f;
        boolean g;

        private C0077b(b bVar) {
            this.f1683a = c.b("Shake.Preview");
            this.f1684b = biz.obake.team.touchprotector.d.i.b.c();
            this.f1685c = !c.b("Sensors.Paused");
            this.f1686d = "Locked".equals(c.c("TPService.State"));
            this.e = "Unlocked".equals(c.c("TPService.State"));
            this.f = biz.obake.team.touchprotector.g.a.g("lock_shake");
            this.g = biz.obake.team.touchprotector.g.a.g("unlock_shake");
        }

        /* synthetic */ C0077b(b bVar, a aVar) {
            this(bVar);
        }
    }

    public b() {
        if (f()) {
            this.f1681d = new d(this, 10, 2, "Shake");
            this.e = false;
        } else if (g()) {
            this.f1681d = new d(this, 1, 2, "Shake");
            this.e = true;
        }
    }

    public static void d(Map<String, String> map) {
        map.put("Shake.Shaken", "true");
        map.put("Shake.Preview", "false");
        map.put("Shake.Force", "0.0");
    }

    public static boolean e() {
        return f() || g();
    }

    private static boolean f() {
        return ((SensorManager) biz.obake.team.android.a.a().getSystemService("sensor")).getDefaultSensor(10) != null;
    }

    private static boolean g() {
        return ((SensorManager) biz.obake.team.android.a.a().getSystemService("sensor")).getDefaultSensor(1) != null;
    }

    private void h() {
        biz.obake.team.touchprotector.log.a.b().d("Shake: Shaken");
        c.f("Shake.Shaken", true);
    }

    private void i() {
        if (!this.f1681d.g()) {
            this.f1681d.h();
            this.g = System.currentTimeMillis();
        }
    }

    /* access modifiers changed from: private */
    public void j() {
        C0077b bVar = new C0077b(this, (a) null);
        boolean z = bVar.f1683a;
        boolean z2 = true;
        boolean z3 = bVar.f1684b && bVar.f1685c && bVar.e && bVar.f;
        if (!bVar.f1684b || !bVar.f1685c || !bVar.f1686d || !bVar.g) {
            z2 = false;
        }
        if (z || z3 || z2) {
            i();
        } else {
            k();
        }
    }

    private void k() {
        if (this.f1681d.g()) {
            this.f1681d.j();
        }
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Can't fix incorrect switch cases order */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void b(java.lang.String r7) {
        /*
            r6 = this;
            int r0 = r7.hashCode()
            r1 = 5
            r2 = 4
            r3 = 3
            r4 = 2
            r5 = 1
            switch(r0) {
                case -2066548004: goto L_0x003f;
                case -938602933: goto L_0x0035;
                case 831789315: goto L_0x002b;
                case 1234742002: goto L_0x0021;
                case 1690883215: goto L_0x0017;
                case 1941415072: goto L_0x000d;
                default: goto L_0x000c;
            }
        L_0x000c:
            goto L_0x0049
        L_0x000d:
            java.lang.String r0 = "Shake.Preview"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 0
            goto L_0x004a
        L_0x0017:
            java.lang.String r0 = "Screen.State"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 1
            goto L_0x004a
        L_0x0021:
            java.lang.String r0 = "lock_shake"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 4
            goto L_0x004a
        L_0x002b:
            java.lang.String r0 = "Sensors.Paused"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 2
            goto L_0x004a
        L_0x0035:
            java.lang.String r0 = "unlock_shake"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 5
            goto L_0x004a
        L_0x003f:
            java.lang.String r0 = "TPService.State"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 3
            goto L_0x004a
        L_0x0049:
            r7 = -1
        L_0x004a:
            if (r7 == 0) goto L_0x0057
            if (r7 == r5) goto L_0x0057
            if (r7 == r4) goto L_0x0057
            if (r7 == r3) goto L_0x0057
            if (r7 == r2) goto L_0x0057
            if (r7 == r1) goto L_0x0057
            goto L_0x0067
        L_0x0057:
            android.os.Handler r7 = r6.f
            r0 = 0
            r7.removeCallbacksAndMessages(r0)
            android.os.Handler r7 = r6.f
            biz.obake.team.touchprotector.features.shake.b$a r0 = new biz.obake.team.touchprotector.features.shake.b$a
            r0.<init>()
            r7.post(r0)
        L_0x0067:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.features.shake.b.b(java.lang.String):void");
    }

    public void onAccuracyChanged(Sensor sensor, int i) {
    }

    public void onSensorChanged(SensorEvent sensorEvent) {
        float[] fArr = sensorEvent.values;
        float f2 = fArr[0];
        float f3 = fArr[1];
        float f4 = fArr[2];
        float sqrt = (float) (Math.sqrt((double) (((f2 * f2) + (f3 * f3)) + (f4 * f4))) / 9.806650161743164d);
        if (this.e) {
            sqrt = Math.abs(sqrt - 1.0f);
        }
        c.g("Shake.Force", String.format(Locale.US, "%1.1f", new Object[]{Float.valueOf(sqrt)}));
        if (sqrt > Float.parseFloat(biz.obake.team.touchprotector.g.a.l("shake_sensitivity"))) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - this.g > 500) {
                h();
                this.g = currentTimeMillis;
            }
        }
    }

    public void start() {
        if (e()) {
            super.start();
            j();
        }
    }

    public void stop() {
        if (e()) {
            super.stop();
            k();
        }
    }
}
